package com.mxnavi.smartd.sdk;

import android.app.Application;
import android.os.Looper;

import com.mxnavi.smartd.sdk.car.CaA50CarAdapter;
import com.mxnavi.smartd.sdk.car.ICarAdapter;
import com.mxnavi.smartd.sdk.database.SmartDDataBase;
import com.mxnavi.smartd.sdk.tsp.CloudServiceImpl;
import com.mxnavi.smartd.sdk.tsp.ICloudService;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author ：zhong.jw
 * @date ：Created in 2024/2/21 17:37
 * <p>
 * 负责与实车动力系统，云端通信的sdk，每增加一个方法要求写下单元测试
 */
public final class SmartDManager {
    private static volatile SmartDManager INSTANCE;

    /**
     * 动力系统相关
     */
    private final ICarAdapter carAdapter = new CaA50CarAdapter();
    /**
     * 云服务相关
     */
    private final ICloudService cloudService = new CloudServiceImpl();

    private final ExecutorService threadPool = Executors.newCachedThreadPool();
    private SmartDDataBase smartDDataBase;

    private SmartDManager() {
    }

    public static SmartDManager getInstance() {
        if (INSTANCE == null) {
            synchronized (SmartDManager.class) {
                if (INSTANCE == null) {
                    INSTANCE = new SmartDManager();
                }
            }
        }
        return INSTANCE;
    }

    /**
     * 初始化相关
     */
    public void init(Application context) {
        //todo
        Looper.getMainLooper().getQueue().addIdleHandler(() -> {
            smartDDataBase = SmartDDataBase.getInstance(context);
            return false;
        });
    }

    /**
     * 获取动力系统接口
     */
    public ICarAdapter getCarAdapter() {
        return carAdapter;
    }

    /**
     * 获取云控接口
     */
    public ICloudService getCloudService() {
        return cloudService;
    }

    /**
     * 数据库接口
     */
    public SmartDDataBase getSmartDDataBase() {
        return smartDDataBase;
    }
}
